package com.anlia.progressbar;

import com.anlia.utils.LinearGradientUtil;

import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Text;
import ohos.agp.render.Paint;
import ohos.agp.utils.Color;

import java.text.DecimalFormat;

public class MainAbility extends Ability {
    // 进度
    private static final int PROGRE_OR = 100;

    // 时间
    private static final int TIME = 5000;

    // 接口回调
    private CircleBarView.OnAnimationListener onAnimationListener = new CircleBarView.OnAnimationListener() {
        @Override
        public String howToChangeText(float interpolatedTime, float updateNum, float maxNum) {
            DecimalFormat decimalFormat = new DecimalFormat("0.00");
            String bar = decimalFormat.format(interpolatedTime * updateNum / maxNum * PROGRE_OR) + "%";
            return bar;
        }

        @Override
        public void howTiChangeProgressColor(Paint paint, float interpolatedTime, float updateNum, float maxNum) {
        }
    };
    private CircleBarView.OnAnimationListener onAnimationListener2 = new CircleBarView.OnAnimationListener() {
        @Override
        public String howToChangeText(float interpolatedTime, float updateNum, float maxNum) {
            DecimalFormat decimalFormat = new DecimalFormat("0.00");
            String bar = decimalFormat.format(interpolatedTime * updateNum / maxNum * PROGRE_OR) + "%";
            return bar;
        }

        @Override
        public void howTiChangeProgressColor(Paint paint, float interpolatedTime, float updateNum, float maxNum) {
            LinearGradientUtil linearGradientUtil = new LinearGradientUtil(Color.YELLOW.getValue(),
                    Color.RED.getValue());
            paint.setColor(new Color(linearGradientUtil.getColor(interpolatedTime)));
        }
    };
    private WaveProgressView.OnAnimationListener animationListener = new WaveProgressView.OnAnimationListener() {
        @Override
        public String howToChangeText(float interpolatedTime, float updateNum, float maxNum) {
            DecimalFormat decimalFormat = new DecimalFormat("0.00");
            String bar = decimalFormat.format(interpolatedTime * updateNum / maxNum * PROGRE_OR) + "%";
            return bar;
        }

        @Override
        public float howToChangeWaveHeight(float percent, float waveHeight) {
            return 0;
        }
    };

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        CircleBarView circleBarView3 = (CircleBarView) findComponentById(ResourceTable.Id_circle3);
        Text text3 = (Text) findComponentById(ResourceTable.Id_progress3);
        circleBarView3.setProgressNum(80, 1800);
        circleBarView3.setText(text3);
        circleBarView3.setOnAnimationListener(onAnimationListener2);
        CircleBarView circleBarView2 = (CircleBarView) findComponentById(ResourceTable.Id_circle2);
        Text text2 = (Text) findComponentById(ResourceTable.Id_progress2);
        circleBarView2.setProgressNum(PROGRE_OR, TIME);
        circleBarView2.setText(text2);
        circleBarView2.setOnAnimationListener(onAnimationListener);
        CircleBarView circleBarView = (CircleBarView) findComponentById(ResourceTable.Id_circle);
        Text text = (Text) findComponentById(ResourceTable.Id_progress);
        circleBarView.setProgressNum(PROGRE_OR, TIME);
        circleBarView.setText(text);
        circleBarView.setOnAnimationListener(onAnimationListener);
        Text waveText = (Text) findComponentById(ResourceTable.Id_wavetext);
        WaveProgressView waveProgressView = (WaveProgressView) findComponentById(ResourceTable.Id_wave);
        waveProgressView.setProgressNum(90,TIME);
        waveProgressView.setText(waveText);
        waveProgressView.setOnAnimationListener(animationListener);
        Text waveText2 = (Text) findComponentById(ResourceTable.Id_wavetext2);
        WaveProgressView waveProgressView2 = (WaveProgressView) findComponentById(ResourceTable.Id_wave2);
        waveProgressView2.setProgressNum(PROGRE_OR,TIME);
        waveProgressView2.setText(waveText2);
        waveProgressView2.setOnAnimationListener(animationListener);
        Text waveText3 = (Text) findComponentById(ResourceTable.Id_wavetext3);
        WaveProgressView waveProgressView3 = (WaveProgressView) findComponentById(ResourceTable.Id_wave3);
        waveProgressView3.setProgressNum(85,TIME);
        waveProgressView3.setDrawSecondWave(true);
        waveProgressView3.setText(waveText3);
        waveProgressView3.setOnAnimationListener(animationListener);
    }
}
